﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.membercenter
{
    public partial class member_main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["MemberName"] != null)
                {
                    this.lbUserInfo.Text = "您好，" + Session["MemberName"].ToString() + "。欢迎您回来！";
                    YXShop.BLL.Member.MemberAccount mabll = new YXShop.BLL.Member.MemberAccount();
                    YXShop.Model.Member.MemberAccount mamodel = mabll.GetModel(Convert.ToInt32(Session["MemberID"].ToString()));
                    if (mamodel != null)
                    {
                        this.lbLogionInfo.Text = "您上一次登录时间：" + mamodel.LastLoginDate +"；登录IP："+mamodel.LastLoginIP+"";
                        this.lbIntegranl.Text = mamodel.Points.ToString();
                        this.lbBalance.Text = mamodel.Capital.ToString();
                        this.lbPeriodOfValidity.Text = mamodel.PeriodOfValidity.ToString();
                        YXShop.BLL.Member.MemberRank mrbll = new YXShop.BLL.Member.MemberRank();
                        YXShop.Model.Member.MemberRank mrmodel = mrbll.GetModel(Convert.ToInt32(mamodel.UserGroup));
                        if (mrmodel != null)
                        {
                            this.lbLve.Text = mrmodel.Name;
                        }
                    }
                    this.litlist.Text = GetOrderListById(Session["MemberName"].ToString());
                }
            }
            
        }

        public string GetOrderListById(string userId)
        {
            YXShop.BLL.Order.Orders bll = new YXShop.BLL.Order.Orders();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = bll.GetListByPage(" and UserId = '" + userId + "'");
            int index = 0;
            table.AddHeadCol("","序号");
            table.AddHeadCol("", "订单编号");
            table.AddHeadCol("", "下单时间");
            table.AddHeadCol("", "收货人");
            table.AddHeadCol("", "支付方式");
            table.AddHeadCol("", "操作");
            table.AddRow();
            string url = string.Empty;
            string test = string.Empty;
            if(dataPage.DataReader!=null)
            {
                while(dataPage.DataReader.Read())
                {
                    url = YXShop.TemplateAction.Common.UrlStr("order_info", "OrderId=" + dataPage.DataReader["Id"].ToString(), "membercenter/order/");
                    index++;
                    table.AddCol((dataPage.PageCount * (dataPage.PageIndex - 1) + index).ToString());
                    table.AddCol("<a href="+url+">" + dataPage.DataReader["OrderId"].ToString() + "</a>");
                    table.AddCol(dataPage.DataReader["OrderDate"].ToString());
                    table.AddCol(dataPage.DataReader["ConsigneeName"].ToString());
                    table.AddCol(GetOrderType(dataPage.DataReader["PaymentType"].ToString()));
                    table.AddCol("&#1769<a href="+url+">查看</a></a>");
                    table.AddRow();
                }
               
            }
            test = table.GetTable() + dataPage.PageToolBar;
            table = null;
            dataPage.Dispose();
            dataPage = null;
            bll = null;
            return test;
        }

        #region 支付类型

        public string GetOrderType(string typeId)
        {
            if (!string.IsNullOrEmpty(typeId))
            {
                YXShop.BLL.SystemInfo.TerraceManage tmbll = new YXShop.BLL.SystemInfo.TerraceManage();
                YXShop.Model.SystemInfo.TerraceManage tmmodel = tmbll.GetModelById(Convert.ToInt32(typeId));
                if (tmmodel != null)
                {
                    return tmmodel.Tmname;
                }
            }
            return string.Empty;
        }
        #endregion
    }
}
